package com.cqie.rbac.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cqie.rbac.bo.TermBo;
import com.cqie.rbac.entity.Term;
import com.cqie.rbac.mapper.TermMapper;
import com.cqie.rbac.service.ITermService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cqie.rbac.util.MyPageHelper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 学期表 服务实现类
 * </p>
 *
 * @author 单机吧
 * @since 2021-10-11
 */
@Service
public class TermServiceImpl extends ServiceImpl<TermMapper, Term> implements ITermService {

    @Override
    public List<Term> pageOfTerm(TermBo bo) {
        if (bo.getPageNum() == null || bo.getPageSize() == null){
            bo.setPageNum(1);
            bo.setPageSize(10);
        }
        MyPageHelper.startPage(bo);
        LambdaQueryWrapper<Term> lqw = Wrappers.lambdaQuery();
        lqw.likeRight(StringUtils.isNotBlank(bo.getTerm_name()),Term::getTermName,bo.getTerm_name());
        lqw.eq(StringUtils.isNotBlank(bo.getYear()),Term::getYear,bo.getYear());
        List<Term> terms = baseMapper.selectList(lqw);
        return terms;
    }
}
